package com.info.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeTool {
	private static TimeTool instance;

	public static TimeTool getInstance() {
		if (instance == null) {
			instance = new TimeTool();
		}
		return instance;
	}

	public int getYears() {
		int year = 2005;
		Calendar calendar = Calendar.getInstance();
		year = calendar.getTime().getYear();
		return year;
	}

	public static String getDateTimeSecond() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public  String getDateTime() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:sss");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public String getDate() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public String getDateTimes() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
		String result = sdf.format(calendar.getTime());
		return result;
	}

	public static long getLongTime(String times) {
		long timel = 0L;
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			timel = sdf.parse(times).getTime();
		} catch (ParseException e) {
			e.printStackTrace();
			return timel;
		}
		return timel;
	}

	public static String dateFormatConversion(String dateString) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date theDate = null;
		try {
			theDate = sdf.parse(dateString);
		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		sdf.applyPattern("yyyyMMddHHmmss");
		return sdf.format(theDate);
	}

	public static void main(String[] str) {
		System.out.print(getInstance().getDateTimes());
		System.out.println(Timestamp.valueOf("2012-10-12 12:12:12"));
		System.out.println(Integer.parseInt("39", 16));
		System.out.println("546886".getBytes());
	}
}